# -*- coding: utf8  -*-

import sys
import os

import gtk
import gtk.glade

from backup_system import backup_system

class RestoreDialog:
	
    def __init__(self, parent):
        builder = gtk.Builder()
        path = os.path.dirname(__file__) + os.sep + 'glade/restoreDialog.glade'
        builder.add_from_file(path)
        
        self.restore_dialog = builder.get_object("restoreDialog")
        self.restore_dialog.set_transient_for(parent)
        
        self.filePackages = builder.get_object("filePackages")
        self.fileSources = builder.get_object("fileSources")
        self.dlg_not_packages = builder.get_object("dlg_not_packages")
        self.dlg_not_sources = builder.get_object("dlg_not_sources")
        
        builder.connect_signals(self)
		
    def on_btnAceptar_clicked(self, widget):
        if self.filePackages.get_filename() == None:
            self.dlg_not_packages.run()
            self.dlg_not_packages.hide()
        elif self.fileSources.get_filename() == None:
            self.dlg_not_sources.run()
            self.dlg_not_sources.hide()
        else:
            backup_system.restore_sources(self.fileSources.get_filename())
            backup_system.restore_packages(self.filePackages.get_filename())
            self.restore_dialog.destroy()
    
    def on_btnCancelar_clicked(self, widget):
        self.restore_dialog.destroy()
